//
//  WatchRecord.m
//  Courses
//
//  Created by YiXuePxh on 15/4/3.
//  Copyright (c) 2015年 boyibang. All rights reserved.
//

#import "WatchRecord.h"
#import "PublicCourse.h"
@implementation WatchRecord

- (id)initWithJson:(id)jsonArray{
    if (self = [super init]) {
        if (![jsonArray isKindOfClass:[NSDictionary class]]) {
            return self;
        }
        NSMutableArray* watchDatas = [[NSMutableArray alloc] init];
        if ([jsonArray[@"courses"] isKindOfClass:[NSArray class]]) {
            for (id courseJson in jsonArray[@"courses"]) {
                WatchData* watchData = [[WatchData alloc] init];
                watchData.markDate = courseJson[@"markTime"];
                watchData.courseId = courseJson[@"courseId"];
                watchData.courseName = courseJson[@"courseName"];
                watchData.courseDescription = courseJson[@"courseDescription"];
                watchData.teacherId = courseJson[@"teacherId"];
                watchData.teacherName = courseJson[@"teacherName"];
                watchData.teacherHeadPhotoUrl = courseJson[@"teacherHeadPhotoUrl"];
                watchData.teacherTitile = courseJson[@"teacherTitile"];
                watchData.courseViewNum = courseJson[@"courseViewNum"];
                watchData.favoritesNum = courseJson[@"favoritesNum"];
                [watchDatas addObject:watchData];
            }
            _watchDatas = [watchDatas mutableCopy];
        }
    }
    return self;
}
+ (NSArray* )getWatchCourseLists{
    NSMutableArray* watchs = [[NSMutableArray alloc]init];
    Request* request = [Request requestWithName:@"play_his"];
//    request.body[@"sourceId"] = @"2";
//    request.body[@"deviceNo"] = @"IOS12345";
//    request.body[@"userId"] = [User currentUser].userId;
    request.body[@"version"] = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
    NSMutableDictionary* page = [[NSMutableDictionary alloc]init];
    [page setValue:@"1" forKey:@"pageNo"];
    [page setValue:@"20" forKey:@"pageSize"];
    request.body[@"page"] = page;
    Response* response = [request response];
    if (response.result) {
        if ([response.content[@"palyHis"] isKindOfClass:[NSArray class]]) {
            for (id jsonArray in response.content[@"palyHis"]) {
                WatchRecord* watchRecord = [[WatchRecord alloc]initWithJson:jsonArray];
                [watchs addObject:watchRecord];
            }
        }
    }
    return [watchs copy];
}

@end
